package com.zh.modules.app.controller;

import com.zh.modules.app.entity.MenuDO;
import com.zh.modules.app.entity.vo.LanguageVO;
import com.zh.modules.app.entity.vo.MenuVO;
import com.zh.modules.app.repository.MenuRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/app")
@Api(tags = "测试")
@Slf4j
public class PermissionController {

    @Autowired
    private MenuRepository menuRepository;

    @GetMapping("/routes")
    @ApiOperation("routes")
    public List<MenuVO> routes() {
        List<MenuDO> list = menuRepository.lambdaQuery().list();
        List<MenuVO> result = list.stream().map(a -> {
            MenuVO menuVO = new MenuVO();
            BeanUtils.copyProperties(a, menuVO);
            menuVO.setZh(LanguageVO.builder().name(a.getZhName()).build());
            return menuVO;
        }).collect(Collectors.toList());
        return result;
    }
}
